package org.hu.flexeasy.components
{
	import flash.display.Graphics;
	
	import mx.core.IVisualElement;
	
	import org.hu.flexeasy.classes.ILoading;
	import org.hu.flexeasy.util.Utils;
	
	import spark.components.Group;
	
	
	/**
	 * <p>
	 *     <b>HUBO 2012-1-20  /  hubo.0508ⓐgmail.com</br>org.hu.flexeasy.components.ContainerGroup.as</b>
	 * </p>
	 */
	public class GroupContainer extends Group implements ILoading
	{
		private var _loadMasks:LoadMasks;
		
		////////////////////////////implements start////////////////////////////
		private var loadIdentification:Boolean = false;
		private var _loadClasses:Class;
		private var _bgColor:uint;
		private var _bgAlpha:Number;
		////////////////////////////implements end////////////////////////////
		
		public var borderSides:String="all";
		public var backgroupColor:uint = 0;
		public var borderColor:uint = 0xB5B8C8;
		
		public function GroupContainer()
		{
			super();
		}
				
		override protected function createChildren():void
		{
			super.createChildren();
			
			if(!loadMasks && loadIdentification)
			{
				loadMasks = new LoadMasks;
				//this.addElement(loadMasks);	
				
				if(this.loadClasses){
					loadMasks.loading = this.loadClasses;
				}
			}
		}
		
		override protected function commitProperties():void
		{
			super.commitProperties();
			
			if(loadMasks)
			{
				loadMasks.x = 0;
				loadMasks.y = 0;
				
				loadMasks.includeInLayout = false;		
				
				//set Property
				
				if(this.bgColor != 0 )
				{
					this._loadMasks.setStyle("backgroundColor",this.bgColor);
				}
				
				if(this.bgAlpha.toString() != "NaN")
				{
					this._loadMasks.setStyle("backgroundAlpha",this.bgAlpha);
				}
			}		
		}
		
		override protected function updateDisplayList(w:Number, h:Number):void
		{
			super.updateDisplayList(w, h);
			
			var g:Graphics=graphics;
			if (isNaN(w) || isNaN(h))
				return;
			g.clear();
			
			Utils.drawBackgroup(backgroupColor,g,w,h);			
			g.lineStyle(1, borderColor);
			Utils.drawBorder(Utils.lineSides(borderSides),g,w,h);
			
			if(loadMasks)
			{
				loadMasks.width = w;
				loadMasks.height = h;
			}						
		}
		
		/**
		 * 启用加载
		 */
		public function startUsing():void
		{
			this.addElementAt(this.loadMasks,this.numElements);
		}
		
		/**
		 * 结束加载
		 */
		public function finishUsing():void
		{ 
			this.removeElement(this.loadMasks);
		}

		public function get loadClasses():Class
		{
			return this._loadClasses;
		}
		
		public function set loadClasses(value:Class):void
		{
			this._loadClasses = value;	
		}
		
		public function get bgColor():uint
		{
			return this._bgColor
		}
		
		public function set bgColor(value:uint):void
		{
			this._bgColor = value;
		}
		
		public function get bgAlpha():Number
		{
			return this._bgAlpha;
		}
		
		public function set bgAlpha(value:Number):void
		{
			this._bgAlpha = value;
		}
		
		/**
		 * 创建容器时，是否创建加载等待提示内容
		 */
		public function get loads():Boolean
		{
			return loadIdentification;
		}
		
		/**
		 * @private
		 */
		public function set loads(value:Boolean):void
		{
			loadIdentification = value;
		}		

		public function get loadMasks():LoadMasks
		{
			return _loadMasks;
		}

		public function set loadMasks(value:LoadMasks):void
		{
			_loadMasks = value;
		}

	}
}